//index.js
var polyvLive = require('../../utils/polyvlive.js');

Page({
    data: {
        title:"-.-",
        logo:"https://livestatic.videocc.net/assets/wimages/pc_images/logo-default.png",
        companyName:"天津盘古科技有限公司",
        video:{},
        uid:'',
        vid:'',
        content:'',
        isShow: false,
        noLive: false
    },
    timeUpdate: function(e) {
        polyvLive.timeUpdate(e);
    },
    videoError: function () {
      // console.log(1)
    },
    onLoad: function (options) {
        this.setData({
            uid: options.uid,
            vid: options.vid
        })
        wx.showLoading({
            title: '加载中...'
        })
    },
    onReady: function () {
        var that = this;
        // var liveUid = "517d5a3804";
        // var liveVid = "213598";
        var liveUid = that.data.uid;
        var liveVid = that.data.vid;
        var liveVideoContext = wx.createVideoContext('polyvLiveVideo');
        polyvLive.getVideo({
            uid: liveUid,
            vid: liveVid,
            videoContext: liveVideoContext,
            success:function(videoInfo){
                console.log(JSON.stringify(videoInfo))
                that.setData({
                    video: {
                        src: videoInfo.src,
                        poster: videoInfo.poster,
                        title: videoInfo.title
                    }
                });
            },
            error:function(res){
                wx.hideLoading()
                console.log(res)
            },
            onApiStatus:function (status) {
                wx.hideLoading()
                if(status == 'end'){
                    that.setData({
                        noLive: true
                    })
                }else{
                    that.setData({
                        isShow: true
                    })
                }
            }
        });
    }
})
